package com.wms.security;

import com.wms.security.filter.UrlFilter;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@Component
public class JWTAuthFilter extends BasicAuthenticationFilter {

    @Resource(name = "adminFilter")
    private UrlFilter adminFilter;


    public JWTAuthFilter(AuthenticationManager authenticationManager) {
        super(authenticationManager);
    }

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        try {
            adminFilter.handler(request, response);
            chain.doFilter(request, response);
        } catch (Exception e){
            e.printStackTrace();
        }
    }



}
